var ServletUtils = function () {
    return this;
};
ServletUtils.prototype = {
    constructor: ServletUtils,

    /**
     * 获取url请求参数.
     * @param name
     * @returns {*}
     */
    get : function (name) {
        var uri = window.location.href;
        if (name && name != null) {
            var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
            var r = uri.substring(uri.indexOf('?') + 1).match(reg);
            return (r != null) ? r[2] : null;
        }

        var args = {};
        var query = uri.substring(uri.indexOf('?') + 1); // 获取查询串
        var pairs = query.split('&'); // 在逗号处断开
        for (var i = 0; i < pairs.length; i++) {
            var pos = pairs[i].indexOf('='); // 查找name=value
            if (pos > -1) {
                var argname = pairs[i].substring(0, pos); // 提取name
                var val = pairs[i].substring(pos + 1); // 提取value
                args[argname] = val; // 存为属性
            }
        }
        return args;
    },

    /**
     * Map对象转换成request query parameters string.
     * @param queryMap
     */
    mapToQueryString: function (queryMap) {
        queryMap = queryMap || {}
        var queryString = "";
        $.each(queryMap, function (key, val) {
            queryString += ("" == queryString ? "" : "&") + key + "=" + val;
        });
        return queryString;
    }
};
window.QiServletUtils = new ServletUtils();